package com.yanqu.road.server.cmd.relatives;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.relatives.RelativesProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.relatives.RelativesMgr;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;

import java.util.Map;

@Cmd(code = Protocol.S_RELATIVES_GET_USER_INFO_BACK, desc = "拿玩家基础数据（返回）")
public class GetUserBaseInfoBackCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {


        RelativesProto.CrossGetUserBaseInfoRespMsg respMsg = RelativesProto.CrossGetUserBaseInfoRespMsg.parseFrom(yanQuMessage.getBytes());

        Map<Long, UserBaseInfo> map =  RelativesMgr.getCacheOtherServerUserMap();
        for (RelativesProto.CrossUserBaseInfoTemp infoTemp : respMsg.getUserList()) {
            map.put(infoTemp.getUserId(), PlayerBasePb.parseToUserBaseInfo(infoTemp.getBaseInfo()));
        }

    }
}
